package org.ww.search.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ww.common.exception.GmallExceptionEnum;
import org.ww.common.to.es.SkuEsModel;
import org.ww.common.utils.R;
import org.ww.search.service.ProductSaveService;

import java.util.List;

/**
 * @program: gmall
 * @description: es保存
 * @author: ww
 * @create: 2024-02-19 15:04
 **/
@Slf4j
@RestController
@RequestMapping("/elastic/save")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    //商品上架
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels){
        boolean b = false;
        try {
             b = productSaveService.productStatusUp(skuEsModels);
        }catch (Exception e){
            log.error("ElasticSaveController商品上架错误:{}",e);
            return R.error(GmallExceptionEnum.PRODUCT_UP_EXCEPTION.getCode(),GmallExceptionEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if(!b){
            return R.ok();
        }else{
            return R.error(GmallExceptionEnum.PRODUCT_UP_EXCEPTION.getCode(),GmallExceptionEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }


}
